﻿#include "widget.h"
#include "ui_widget.h"

#include "cPlayer.h"

#include <QDebug>

#include <crtdbg.h>
#include <assert.h>

#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    m_p = NULL;
}

Widget::~Widget()
{
	delete m_p;
    delete ui;
}

void Widget::closeEvent(QCloseEvent *ev)
{
    Q_UNUSED(ev);
    if(m_p)
        m_p->stop();
}

void Widget::on_btnOpen_clicked()
{
    if(m_p)
        return ;
    m_p = new cPlayer;
    connect(ui->widgetPlayerControl, SIGNAL(stop()), this, SLOT(slot_stop()));

    m_p->setMediaFile("C:/Users/Public/Videos/Sample Videos/1.MKV");
    if (!m_p->start()) {
        qDebug()<<"stop";
        m_p->stop();
        delete m_p;
        m_p = NULL;
    }
    else {
        qDebug()<<"m_p start succeed";
    }
}

void Widget::slot_stop()
{
    if(!m_p)
        return ;
    disconnect(ui->widgetPlayerControl, SIGNAL(stop()), this, SLOT(slot_stop()));
    m_p->stop();
    delete m_p;
    m_p = NULL;
}
